package javabase.schoolwork.day6_10;

/**
 * @author fance
 * @date 2018/6/10 13:13
 */
class ThreadI extends  Thread {
    private Object lock;

    public ThreadI(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            synchronized (lock) {
                System.out.println("开始  wait  ：" + System.currentTimeMillis());
                lock.wait();
                System.out.println("结束  wait  ：" + System.currentTimeMillis());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class ThreadII extends  Thread {
    private Object lock;

    public ThreadII(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {

            synchronized (lock) {
                System.out.println("开始  notify  ：" + System.currentTimeMillis());
                lock.notify();
                System.out.println("结束  notify  ：" + System.currentTimeMillis());
            }

    }
}
public class WaitTest {
    public static void main(String[] args) {
        try {
            Object lock = new Object();
            ThreadA threadA = new ThreadA(lock);
            threadA.start();
            Thread.sleep(50);
            ThreadB threadB = new ThreadB(lock);
            threadB.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }/* try {
            Object lock = new Object();
            ThreadI threadI = new ThreadI(lock);
            threadI.start();
            Thread.sleep(3000);
            ThreadII threadII = new ThreadII(lock);
            threadII.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        /*try {
            String lock = new String();
            System.out.println("syn 上面");
            synchronized (lock) {
                System.out.println("syn 第1行");
                lock.wait();
                System.out.println("wait xia ...");
            }
            System.out.println("syn xia ...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
    }
}
